/**

 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
]

export const asyncRoutes = [
  {
    path: '/users-management',
    component: Layout,
    redirect: 'noRedirect',
    hidden: false,
    meta: {
      title: '用户管理',
      icon: 'users',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'list',
        name: 'UsersList',
        component: () => import('@/views/users/list'),
        meta: {
          title: '用户列表',
          icon: 'user-friends',
          permissions: ['admin'],
        },
      },
      {
        path: 'resident',
        name: 'UsersResident',
        component: () => import('@/views/users/resident'),
        meta: {
          title: '驻场人员',
          icon: 'people-carry',
          permissions: ['admin'],
        },
      },
      {
        path: 'develop',
        name: 'UsersDevelop',
        component: () => import('@/views/users/develop'),
        meta: {
          title: '开发商审核',
          icon: 'laptop-code',
          permissions: ['admin'],
        },
      },
    ],
  },
  {
    path: '/building',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '项目管理',
      icon: 'building',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'list',
        name: 'BuildingList',
        component: () => import('@/views/building/list'),
        meta: {
          title: '项目列表',
          icon: 'list',
          permissions: ['admin'],
        },
      },
      {
        path: 'add',
        name: 'BuildingAdd',
        component: () => import('@/views/building/add'),
        meta: {
          title: '添加项目',
          icon: 'plus-square',
          permissions: ['admin'],
        },
      },
    ],
  },
  {
    path: '/house',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '房屋管理',
      icon: 'home',
    },
    children: [
      {
        path: 'list',
        name: 'HouseList',
        component: () => import('@/views/house/list'),
        meta: {
          title: '房屋列表',
          icon: 'warehouse',
        },
      },
      {
        path: 'add',
        name: 'HouseAdd',
        component: () => import('@/views/house/add'),
        meta: {
          title: '添加房屋',
          icon: 'plus-circle',
        },
      },
    ],
  },
  {
    path: '/feature',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '功能维护',
      icon: ' ',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'feature_tree',
        name: 'MapTree',
        component: () => import('@/views/feature/features'),
        meta: {
          title: '检查项维护',
          icon: 'tree',
        },
      },
      {
        path: 'safe_problem_tree',
        name: 'Safe',
        component: () => import('@/views/feature/problem'),
        meta: {
          title: '安全问题维护',
          icon: 'question',
        },
      },
      {
        path: 'quality_problem',
        name: 'Quality',
        component: () => import('@/views/feature/quality'),
        meta: {
          title: '质量问题维护',
          icon: 'question',
        },
      },
      {
        path: 'tags',
        name: 'Tags',
        component: () => import('@/views/feature/tag'),
        meta: {
          title: '标签管理',
          icon: 'tags',
          permissions: ['admin'],
        },
      },
    ],
  },
  {
    path: '/editor',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '文字编辑',
      icon: 'edit',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'index',
        name: 'EditorIndex',
        component: () => import('@/views/editor/index'),
        meta: {
          title: '基本配置',
          icon: 'pen-square',
        },
      },
      {
        path: 'state',
        name: 'State',
        component: () => import('@/views/editor/state'),
        meta: {
          title: '权限协议',
          icon: 'exclamation',
        },
      },
      {
        path: 'list',
        name: 'EditorList',
        component: () => import('@/views/editor/list'),
        meta: {
          title: '动态资讯',
          icon: 'pencil-alt',
        },
      },
    ],
  },
  {
    path: '/check',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '审核管理',
      icon: 'flag-checkered',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'progress',
        name: 'ProgressCheck',
        component: () => import('@/views/check/progress'),
        meta: {
          title: '进度审核',
          icon: 'chart-line',
        },
      },
      {
        path: 'question',
        name: 'Question',
        component: () => import('@/views/check/question'),
        meta: {
          title: '问题审核',
          icon: 'question',
        },
      },
      {
        path: 'note',
        name: 'Note',
        component: () => import('@/views/check/note'),
        meta: {
          title: '事记节点审核',
          icon: 'sticky-note',
        },
      },
      {
        path: 'audit',
        name: 'HouseAudit',
        component: () => import('@/views/house/audit'),
        meta: {
          title: '绑定房源审核',
          icon: 'check-double',
        },
      },
    ],
  },
  {
    path: '/setting',
    component: Layout,
    redirect: 'noRedirect',
    meta: {
      title: '系统设置',
      icon: 'cogs',
      permissions: ['admin'],
    },
    children: [
      {
        path: 'ad',
        name: 'AD',
        component: () => import('@/views/setting/ad'),
        meta: {
          title: '广告配置',
          icon: 'tv',
        },
      },
      {
        path: 'app',
        name: 'App',
        component: () => import('@/views/setting/appPkg'),
        meta: {
          title: 'APP上传',
          icon: 'cloud-upload-alt',
        },
      },
      {
        path: 'logs',
        name: 'Logs',
        component: () => import('@/views/setting/log'),
        meta: {
          title: '日志管理',
          icon: 'sticky-note',
        },
      },
      {
        path: 'want',
        name: 'Want',
        component: () => import('@/views/setting/want'),
        meta: {
          title: '招募令',
          icon: 'network-wired',
        },
      },
      {
        path: 'wish',
        name: 'Wish',
        component: () => import('@/views/setting/wish'),
        meta: {
          title: '愿望池',
          icon: 'star-and-crescent',
        },
      },
    ],
  },
  {
    path: '/personnelManagement',
    component: Layout,
    redirect: 'noRedirect',
    hidden: false,
    name: 'PersonnelManagement',
    meta: { title: '管理员配置', icon: 'users-cog', permissions: ['admin'] },
    children: [
      {
        path: 'userManagement',
        name: 'UserManagement',
        component: () =>
          import('@/views/personnelManagement/userManagement/index'),
        meta: { title: '管理员列表', icon: 'user-plus' },
      },
      {
        path: 'roleManagement',
        name: 'RoleManagement',
        component: () =>
          import('@/views/personnelManagement/roleManagement/index'),
        meta: { title: '角色管理', icon: 'user-shield' },
      },
    ],
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
